// let baseUrl = "https://mall.anheyuan.cn"
const api = {
	async get(url) {
		try {
			let res = await axios.get(url)
			res = res.data
			return new Promise((resolve) => {
				resolve(res)
				// if (res.code == 200) {
				// 	resolve(res)
				// } else {
				// 	console.log("获取失败");
				// 	alert('获取失败')
				// 	return
				// }
			})
		} catch (err) {

		}
	},
	async post(url, data) {
		try {
			let datas = this.formatFormData(data)
			let res = await axios.post(baseUrl + url, datas, {
				// headers: {
				// 	'token': window.sessionStorage.getItem('token')
				// }
			})
			res = res.data
			return new Promise((resolve) => {
				if (res.code == 200) {
					resolve(res)
				} else {
					console.log("获取失败");
					return
				}
			})
		} catch (err) {

		}
	},
	// json 转formdata
	formatFormData(obj) {
		var fd = new FormData();
		for (var key in obj) {
			fd.append(key, obj[key])
		}
		return fd;
	},
}
